package com.involveinnovation.chatserver.controller;

import com.involveinnovation.chatserver.controller.Model.Message2;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.io.IOException;
import java.util.ArrayList;

@RestController
public class DemoController {

    @GetMapping("index")
    public ResponseEntity<String> index(){
        return ResponseEntity.ok("请求成功");
    }

    @GetMapping("page")
    public ModelAndView page() {
        return new ModelAndView("websocket");
    }

    @RequestMapping("/push")
    public ResponseEntity<String> pushToWeb(@RequestBody Message2 message) throws IOException {
        WebSocketServer.sendInfoBySystem(message);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @RequestMapping("/send_to_all")
    public ResponseEntity<String> sendToAll(@RequestBody Message2 message) throws IOException {
        WebSocketServer.sendInfoByUser(message);
        return ResponseEntity.ok("MSG SEND SUCCESS");
    }

    @GetMapping("/get_online_user")
    public String getOnlineUser() throws IOException {
        String list = WebSocketServer.getOnlineUser();
        return list;
        // return ResponseEntity.ok("查询在线用户成功");
    }

}
